package abel.wlmr.model;

import java.util.ArrayList;
import java.util.List;

import abel.wlmr.model.type.DataIdBody;
import io.netty.buffer.ByteBuf;

public class WlmrDefaultPart extends WlmrBasePart {

    /**
     * 
     */
    public WlmrDefaultPart() {
        super();
    }

    /**
     * @param guessedLen
     */
    public WlmrDefaultPart(short guessedLen) {
        super(guessedLen);
    }

    @Override
    public int parseBuf(ByteBuf buf) throws WlmrException {
        if (checkBuffer(buf) < 0) {
            return -1;
        }

        id = new DataIdBody();
        id.parseBuf(buf);
        short len = (short) (getGuessedLength() - DataIdBody.FIXED_LEN);

        List<WlmrBaseUnit> units = new ArrayList<>();
        unitList.add(units);

        WlmrDefaultUnit unit = new WlmrDefaultUnit(len);
        unit.parseBuf(buf);
        units.add(unit);

        return getGuessedLength();
    }

    @Override
    public int getMinLength() {
        return DataIdBody.FIXED_LEN;
    }

}
